/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.util;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Locale;
/**
 * @author Administrador.
 */
public class UtilDate {
    public static String getDateTime() {	
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(Calendar.getInstance().getTime());
    }
    
    public static String getFechaHoraNormal() {	
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        return dateFormat.format(Calendar.getInstance().getTime());
    }
    
    public static String getFechaNormal() {	
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        return dateFormat.format(Calendar.getInstance().getTime());
    }
    
    public static String getFechaSqlActual() {	
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return dateFormat.format(Calendar.getInstance().getTime());
    }
    
    public static String getFechaSqlString(Calendar c){
        java.sql.Date sqlDate = new java.sql.Date(c.getTimeInMillis());
        return sqlDate.toString();
    }
    
    public static int getPeriodo(){
        DateFormat dateFormat = new SimpleDateFormat("yyyyMM");
        return Integer.parseInt(dateFormat.format(Calendar.getInstance().getTime()));
    }
    public static int getYear(){
        DateFormat dateFormat = new SimpleDateFormat("yyyy");
        return Integer.parseInt(dateFormat.format(Calendar.getInstance().getTime()));
    }
    public static long getFecha_yyyyMMdd(){
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        return Long.parseLong(dateFormat.format(Calendar.getInstance().getTime()));
    }
    
    public static String convertirFechaSql_A_fechaNormal(String fechaSql){
        return fechaSql.substring(8)+"/"+fechaSql.substring(5,7)+"/"+fechaSql.substring(0,4);
    }
    
    public static String convertirFechaNormal_A_fechaSql(String fecha){
        return fecha.substring(6)+"-"+fecha.substring(3,5)+"-"+fecha.substring(0,2);
    }
    
    public static String getHoraActual() {	
        DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        return dateFormat.format(Calendar.getInstance().getTime());
    }
    
    public static String getFechaActualDetallado(){
        Calendar fecha = Calendar.getInstance();
        SimpleDateFormat formateador = new SimpleDateFormat("EEEE',' dd 'de' MMMM 'de' yyyy 'Hrs.:' HH:mm:ss", new Locale("ES"));
        return formateador.format(fecha.getTimeInMillis());
    }
    
    public static Calendar getCalendar3(String stringDataTime) throws ParseException{
        SimpleDateFormat timeFormatStored = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.util.Date date1 = timeFormatStored.parse(stringDataTime);
        Calendar fecha = Calendar.getInstance();
        fecha.setTime(date1);
        return fecha;
    }
    
    public static Calendar getCalendar(String stringDateSql) throws ParseException{
        SimpleDateFormat timeFormatStored = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date date1 = timeFormatStored.parse(stringDateSql);
        Calendar fecha = Calendar.getInstance();
        fecha.setTime(date1);
        return fecha;
    }
    
    public static Calendar getCalendar2(String stringDateNormal) throws ParseException{
        SimpleDateFormat timeFormatStored = new SimpleDateFormat("dd/MM/yyyy");
        java.util.Date date1 = timeFormatStored.parse(stringDateNormal);
        Calendar fecha = Calendar.getInstance();
        fecha.setTime(date1);
        return fecha;
    }
}
